(function( $ ){
$.alert = function( options , callback) {
var $alert = new Object () , classmod

$alert.conf = {
	"text"			: "" ,
	"appendTo"		: "body" ,
	"css"			: null ,
	"fadeIn"		: false ,
	"fadeInTime"	: 300 ,
	"fadeInDelay"	: 0 ,
	"fadeOut"		: false ,
	"fadeOutTime"	: 300 ,
	"fadeOutDelay"	: 2000 ,
	"class"			: "alert-engine alert" ,
	"addClass"		: "" ,
	"addHtml"		: null ,
	"showClose"		: false ,
	"cssClose"		: null ,
	"onStart"		: null ,
	"onVisible"		: null ,
	"onFade"		: null ,
	"onClosed"		: null
}

if ( options ) { 
	$.extend( $alert.conf , options );
}

$alert.conf.fadeOutDelay=parseInt($alert.conf.fadeOutDelay);
$alert.conf.fadeOutTime=parseInt($alert.conf.fadeOutTime);

classmod="."+$alert.conf.class.replace(" ",".");

$($alert.conf.appendTo).append('<div class="'+$alert.conf.class+' '+$alert.conf.addClass+'"></div>');

$alert.el = $($alert.conf.appendTo).find(classmod).last();

$alert.el.text($alert.conf.text).append($alert.conf.addHtml);

if ( ( $alert.conf.showClose == true ) || ( $alert.conf.showClose == "true" ) ) {
	
	$alert.closeHtml = '<span class="closeButton">&times;</span>';
	$alert.el.append( $alert.closeHtml );
	
	if ( $alert.conf.cssClose ) {
		$alert.el.find( ".closeButton" ).css( $alert.conf.cssClose );
	}
	
	$alert.el.find( ".closeButton" ).click(function () {
		$alert.el.remove();
		if ( typeof $alert.conf.onClosed  == "function" ) {
			$alert.conf.onClosed.call(this);
		}
	});
	
	if ( $alert.conf.css ) {
		$alert.el.css( $alert.conf.css );
	}
}

if ( typeof $alert.conf.onStart  == "function" ) {
	$alert.conf.onStart.call(this);
}

if ( typeof callback  == "function" ) {
	callback.call(this);
}

if ( ( $alert.conf.fadeIn == "true" ) || ( $alert.conf.fadeIn == true ) ) {
	
	$alert.el.hide();
	
	$alert.el.delay( $alert.conf.fadeInDelay ).fadeIn( $alert.conf.fadeInTime, function () {
		if ( typeof $alert.conf.onVisible  == "function" ) {
			$alert.conf.onVisible.call(this);
		}
	});
	
}

if ( ( $alert.conf.fadeOut == "true" ) || ( $alert.conf.fadeOut == true ) ) {

	$alert.fadeOutTimer = setTimeout(function () {
		
		if ( typeof $alert.conf.onFade  == "function" ) {
			$alert.conf.onFade.call(this);
		}
		
		$alert.el.fadeOut( $alert.conf.fadeOutTime , function () {
			$(this).remove();
			if ( typeof $alert.conf.onClosed  == "function" ) {
				$alert.conf.onClosed.call(this);
			}
		});
		
	}, $alert.conf.fadeOutDelay );

}

};
})( jQuery );

(function( $ ){
$.fn.alert = function( options , callback ) {
var conf;

conf = {
	"event"	: "click",
}

if ( options ) { 
	$.extend( conf , options );
}

this.bind( conf.event , function () {
	$.alert( conf , callback );
});

};
})( jQuery );